<template>
  <div class="columninfom">
    <div class="content-wrap my-search">
      <el-form
        :model="queryParams"
        size="mini"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
      >
        <el-form-item label="文章标题">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入文章标题"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="loading" :data="tableData">
      <el-table-column type="index" label="序号" width="50"> </el-table-column>
      <el-table-column
        prop="header"
        label="文章标题"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <span
            @click="getArticleUrl(scope.row)"
            style="color: #009a94; cursor: pointer"
            >{{ scope.row.header }}</span
          >
        </template>
      </el-table-column>

      <el-table-column
        prop="operator"
        label="删除人员"
        width="200"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.operator || "--" }}
        </template>
      </el-table-column>

      <el-table-column
        prop="updatedDate"
        label="删除时间"
        width="200"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.updatedDate || "--" }}
        </template>
      </el-table-column>

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click="handleRecy(scope.row)"
            v-hasPermi="['system:recycle:update']"
            >还原</el-button
          >
          <el-button
            type="text"
            size="small"
            @click="handleDel(scope.row)"
            v-hasPermi="['system:recycle:remove']"
            >彻底删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
//读取文章接口调用,删除文章接口调用
import {
  getRecycleArticle,
  delRecycleArticle,
  recycleRecycleArticle,
  personRecycleArticle,
} from "@/api/content/recyclingStation";
import { articleViewUrl } from "@/api/content/mywork";

export default {
  props: {
    siteRow: Object,
  },
  data() {
    return {
      loading: false,
      showSearch: true,
      tableData: [
        {
          header: "",
          operator: "",
          deletedDate: "",
          createdDate: "",
        },
      ],
      total: 0,
      queryParams: {
        dictType: this.$route.params && this.$route.params.dictType,
        pageNum: 1,
        pageSize: 10,
        postCode: undefined,
        header: undefined,
        operator: undefined,
        deletedDate: undefined,
        createdDate: undefined,
      },
      options: [{ value: "选项1", label: "文章标题" }],
      value: "",
      recycleArticle: {},
    };
  },

  components: {},

  computed: {},

  mounted() {
    //读取表格数据
    this.getList();
  },

  methods: {
    //生成文章访问连接
    getArticleUrl(row) {
      articleViewUrl({
        articleId: row.articleId,
      }).then((res) => {
        let href = res.msg;
        window.open(href, "_blank");
      });
    },

    //删除回收站文章信息
    handleDel(row) {
      this.$confirm("此操作将彻底删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //let articleId = 531;
          delRecycleArticle({ articleId: row.articleId }).then((res) => {
            if (res.code == 200) {
              this.getList();
            }
            // this.tableData = res.data.list;
          });
          this.msgSuccess("删除成功");
        })
        .catch(() => {
          this.msgSuccess("已取消删除");
        });
    },
    //还原回收站文章信息
    handleRecy(row) {
      this.$confirm("此操作将还原该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          recycleRecycleArticle({ articleId: row.articleId }).then((res) => {
            if (res.code == 200) {
              this.getList();
            }
          });
          this.msgSuccess("还原成功");
        })
        .catch(() => {
          this.msgSuccess("已取消还原");
        });
    },
    //读取回收站文章信息
    getList() {
      this.queryParams.siteId = this.siteRow?.siteId || 0;
      getRecycleArticle(this.queryParams).then((res) => {
        this.tableData = res.data.list;
        this.total = res.data.totalCount;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>

<style scoped lang="scss">
.columninfom {
  .el-select {
    margin: 0 15px 0 0;
  }
  height: 100%;
  .el-table {
    width: 100%;
  }
}
</style>
